package qf.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import qf.config.AsyncConfig;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

@Service
public class MyService {

    @Autowired
    private AsyncConfig executor;

    @Async
    public Future<String> doSomething(){
        System.out.println(Thread.currentThread().getName());

        return new AsyncResult<>("hello");
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        AsyncConfig asyncConfig=new AsyncConfig();
        Future<String> result = new MyService().doSomething();
        Future<String> result2 = new MyService().doSomething();
        System.out.println(123);
        String s = result.get();
        System.out.println(s);
    }
}
